package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import util.StrConvert;

import com.dao.ObjectDao;
import com.pro.bean.Unit;

public class EditCmpServlet extends HttpServlet {

	/**
	 * ������Ϣ�����༭ҳ��
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String cmpid=StrConvert.ToCN(request.getParameter("unitId"));
		System.out.println(cmpid);
		String cmpname=StrConvert.ToCN(request.getParameter("unitname"));
		
		//System.out.println("editCmpServlet:"+cmpname);
		
		HttpSession session=request.getSession();
		session.setAttribute("cmpid", cmpid);
		session.setAttribute("cmpname", cmpname);
		
		RequestDispatcher dispatcher=request.getRequestDispatcher("../gxr/admin_cmpinfo_e.jsp");
		dispatcher.forward(request, response);
	}

	/**
	 * ���༭����Ϣ�ύ����ݿ�
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String cmpname=StrConvert.ToCN(request.getParameter("unitname"));
		String cmpid=(String)request.getParameter("unitid");
		
		Unit unit=new Unit();
		unit.setUnitname(cmpname);
		unit.setUnitid(Integer.parseInt(cmpid));
		ObjectDao objectDao =new ObjectDao();
		try {
			objectDao.updates(unit);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		RequestDispatcher dispatcher=request.getRequestDispatcher("SearchCmpServlet");
		dispatcher.forward(request, response);
	}

}
